package com.letoo.sso.core.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.letoo.sso.common.utils.AssertUtil;
import com.letoo.sso.core.service.NewUserService;
import com.letoo.sso.dataaccess.dao.db.BaseDBDAO;
import com.letoo.sso.dataaccess.dao.db.NewUserDBDAO;
import com.letoo.sso.dataaccess.domain.dbo.NewUserDO;

/**
 * 新用户信息服务接口实现
 * 
 * @author: dengjie
 */
@Service("newUserService")
public class NewUserServiceImpl extends BaseServiceImpl<NewUserDO> implements NewUserService {

    @Resource
    private NewUserDBDAO newUserDBDAO;

    @Override
    protected BaseDBDAO<NewUserDO> getDAO() {
        return newUserDBDAO;
    }

    @Override
    public Integer saveNewUser(NewUserDO newUserDO) {
        AssertUtil.gt(newUserDO.getUserId(), 0l, "the userId must be gt zero.userId is:" + newUserDO.getUserId());
        AssertUtil.isTrue(newUserDO.isFirstRegistration(), "the isFirstRegistration must be true");
        return newUserDBDAO.save(newUserDO);
    }

    @Override
    public boolean queryNewUserByUserId(long userId) {
        AssertUtil.gt(userId, 0l, "the userId must be gt zero.userId is:" + userId);
        NewUserDO nu = newUserDBDAO.queryNewUserByUserId(userId);
        if (nu == null) {
            return false;
        }
        return nu.isFirstRegistration();
    }

    @Override
    public boolean queryIsFinishPutawayGuidanceByUserId(long userId) {
        AssertUtil.gt(userId, 0l, "the userId must be gt zero.userId is:" + userId);
        NewUserDO nu = newUserDBDAO.queryNewUserByUserId(userId);
        if (nu == null) {
            return true;
        }
        return nu.isFinishPutawayGuidance();
    }

}
